package com.example.demo.mapper;

import com.example.demo.entity.Company;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CompanyMapper {
    // 创建公司
    @Insert("INSERT INTO company(cid, cname, cmanager, cphone, cfreedays, crate, isdeleted, cbelong) " +
            "VALUES(#{cid}, #{cname}, #{cmanager}, #{cphone}, #{cfreedays}, #{crate}, #{isdeleted}, #{cbelong})")
    int createCompany(Company company);

    // 根据ID删除公司
    @Delete("DELETE FROM company WHERE cid = #{cid}")
    int deleteCompany(Integer cid);

    // 逻辑删除公司
    @Update("UPDATE company SET isdeleted = 1 WHERE cid = #{cid}")
    void updateIsdeleted(Integer cid);

    // 更新公司信息
    @Update("UPDATE company SET cname = #{cname}, cmanager = #{cmanager}, cphone = #{cphone}, " +
            "cfreedays = #{cfreedays}, crate = #{crate} WHERE cid = #{cid}")
    int updateCompany(Company company);

    // 根据ID查询公司
    @Select("SELECT * FROM company WHERE cid = #{cid}")
    Company findCompanyById(Integer cid);

    // 查询所有公司
    @Select("SELECT * FROM company WHERE isdeleted = 0")
    List<Company> findAllCompanies();

}
